﻿using Castle.Facilities.WcfIntegration;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using CoreComponents.DataAccess;
using Crowler.Model.CoreComponents;
using Crowler.Model.CoreComponents.DataAccess;

namespace CoreComponents.Installers
{
    public class CoreComponentsInstaller :IWindsorInstaller
    {
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(
                Component.For<IAppEnvironment>().
                    ImplementedBy<AppEnvironment>().
                    Named("AppEnvironment").
                    LifeStyle.Singleton
                );

            container.Register(
                Component.For<IDataAccessManager>().
                    ImplementedBy<DataAccessManager>().
                    Named("DataAccessManager").
                    LifeStyle.PerWcfOperation()
                );

            container.Register(
                Component.For<IUnitOfWorkFactory>().
                    ImplementedBy<UnitOfWorkFactory>().
                    Named("UnitOfWorkFactory").
                    LifeStyle.Transient
                );
            
            container.Register(
                Component.For<ISessionProvider>().
                    ImplementedBy<SessionProvider>().
                    Named("SessionProvider").
                    LifeStyle.Transient
                );

            container.Register(
                Component.For<INHibernateConfigurationProvider>().
                    ImplementedBy<NHibernateConfigurationProvider>().
                    Named("NHibernateConfigurationProvider").
                    LifeStyle.Singleton
                );

            container.Register(
                Component.For(typeof(IBusinessServiceFacility<,,,>)).
                    ImplementedBy(typeof(BusinessServiceFacility<,,,>)).
                    LifeStyle.Transient
                );

            container.Register(
                Component.For(typeof(IBusinessService<,>)).
                    ImplementedBy(typeof(BusinessServiceDecorator<,>)).
                    Named("BSDecorator").
                    LifeStyle.Transient
                );


           //container.Register(
           //                Classes.FromAssemblyNamed("CoreComponents").
           //                    BasedOn(typeof(IBusinessService<,>)).
           //                    LifestyleTransient().WithService.Base().
           //                    Configure(component => component.Named(component.Implementation.Name))
           //                );

            
        }
    }
}
